package ytdp.careagle.com.ytdp.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import ytdp.careagle.com.ytdp.app.G;
import ytdp.careagle.com.ytdp.mvp.mode.LoginModel;
import ytdp.careagle.com.ytdp.mvp.view.IInputPhoneView;
import ytdp.careagle.com.ytdp.net.MyObserver;
import ytdp.careagle.com.ytdp.net.Result;
import ytdp.careagle.com.ytdp.utils.MobileCheckUtils;

/**
 * Created by admin on 2017/10/13.
 */

public class InputPhonePresenter {
    private IInputPhoneView view;
    private LoginModel model;

    public InputPhonePresenter(IInputPhoneView view) {
        this.view = view;
        model = new LoginModel();
    }


    public void inputPhone(Context context) {
        String phone = view.getPhone();
        String valuationQueryId = view.getValuationQueryId();
        if (!MobileCheckUtils.isMobileNO(phone)) {
            view.showMessage("请输入正确的手机号!");
            return;
        }
        view.showProgress("请稍等");
        model.saveCustomer(context, G.getHeader(context), phone, valuationQueryId, new MyObserver<Result>() {
            @Override
            public void onNext(Result result) {
                super.onNext(result);
                if (result.getCode() == G.REQUEST_OK) {
                    view.saveSuccess();
                } else {
                    view.showMessage(result.getMessage());
                }
                view.hideProgress();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showMessage("保存失败");
                view.hideProgress();
            }
        });
    }
}
